	
	var procDefId   = 0;
	var procDefName = ""
	var pageCount   = 1;
	var procDefNum  = 0;
	var procNames   = null;
	var currentPageType = 0;
	var currentPageIndex = 1;
	
	function initPage(){
		loadAllProcessDefinitions();
	}
	
	/**************************************查询出所有的工作流****************************************/
	function loadAllProcessDefinitions(){
		currentPageType = 0;
		if(isDeptManager()){
			findDepartmentProcessDefinition();
			return;
		}
		CtitJbpmAction.findAllProcessDefinition(loadAllProcessDefinitionsBack)
	}
	
	function loadProcessDefinitionByName(){
		var name = document.getElementById("value").value;
		if(name){
			if(isDeptManager()){
				CtitJbpmAction.findDepartmentProcessDefinitionByPartOfName(procNames, name, loadProcessDefinitionByNameBack);
				return;
			}
			CtitJbpmAction.findProcessDefinitionByPartOfName(name, loadProcessDefinitionByNameBack);
		} else {
			alertMessage("请输入查询关键字");
		}
	}
	
	function loadProcessDefinitionByNameBack(oData){
		list_pager = new Pager(oData,setDataToProcessTable,"list_pager",10);
        var data = list_pager.getItemArray();
        setDataToProcessTable(data);
        list_pager.generatePageNavigation(document.getElementById("process_page_nav"));
        list_pager.generatePageNavigation(document.getElementById("process_page_nav_top"));
	}
	
	function loadAllProcessDefinitionsBack(oData){
		var pageSize = 13;
		pageCount = Math.round(oData.length/pageSize);
		procDefNum = oData.length; 
        if(oData.length > pageCount*pageSize){
           pageCount++;  
        }
	    var innerhtml = "<table cellSpacing='0' cellPadding='0' width='100%' border='0' id='table17'>" + 
				            "<tr>" +
					      	  "<td width='2%'></td>" +
							  "<td align='right' width='100%' height='1'>" +
							  "<font color='#104194'>共 " + pageCount + " 页&nbsp;" + oData.length + " 条记录" +							
							  "&nbsp;&nbsp;<a href='javascript:gotoFirstPage(" + pageSize + ");'>" +
							  "<font color='#104194'>首页</font></a>" +
							  "&nbsp;&nbsp;<a href='javascript:gotoPreviousPage(" + pageSize + ");'>" +
							  "<font color='#104194'>上一页</font></a>" +
							  "&nbsp;&nbsp;<a href='javascript:gotoNextPage(" + pageSize + ");'>" +
							  "<font color='#104194'>下一页</font></a>" +
							  "&nbsp;&nbsp;<a href='javascript:gotoLastPage(" + pageSize + ");'>" +
							  "<font color='#104194'>最后一页</font></a> </font></td>" +
					      "</tr>" +
				      "</table>";
		var div = document.getElementById("process_page_nav");
		var div_top = document.getElementById("process_page_nav_top");
		div.innerHTML = innerhtml;
		div_top.innerHTML = innerhtml;
		
	   	var reflushDiv = document.getElementById("reflush");
	   	var searchDiv = document.getElementById("search");
	   	var importDiv = document.getElementById("import");
	   	var exportDiv = document.getElementById("export");
	   	
	   	if(reflushDiv) reflushDiv.style.display = "block";
	   	if(importDiv) importDiv.style.display = "block";
	   	if(exportDiv) exportDiv.style.display = "block";
		
		gotoFirstPage(pageSize);	
	}
	
	function deleteProcessDefinition(procDefId){
	 	var alertdialog_6 = new YAHOO.widget.SimpleDialog('alert_6', {
	        fixedcenter: true,
	        visible: false,
	        modal: true,
	        width: '300px',
	        constraintoviewport: true, 
	        icon: YAHOO.widget.SimpleDialog.ICON_WARN,
	        buttons: [
	            { text: '确定', handler: function() {
	                alertdialog_6.hide();
	                CtitJbpmAction.deleteProcessDefinition(procDefId, deleteProcessDefinitionBack);
	            }, isDefault: true },
	            { text: '取消', handler: function() {
	                alertdialog_6.hide();
	            }, isDefault: false }
	        ]
    	});
    	alertMessage_6 = function( message ) {
	        alertdialog_6.setHeader('提示');
	        alertdialog_6.setBody('Notta');
	        alertdialog_6.render(document.body);
	        alertdialog_6.setBody(message);
	        alertdialog_6.cfg.setProperty('icon', YAHOO.widget.SimpleDialog.ICON_WARN);
	        alertdialog_6.bringToTop();
	        alertdialog_6.show();
	    };
		alertMessage_6("确定要删除吗？");
	}

	/*
		删除工作流
	*/
	function deleteProcessDefinitionBack(data){
		alertInfo("删除成功.");
		loadAllProcessDefinitions();
	}
	
	/*
		打开工作流的定义XML
	*/
	function openProcessDefinitionXML(procDefId){
		window.open("processxml.html?procDefId="+procDefId,"显示审批流程的定义XML",
					"height=500,width=700,scrollbars=yes,toolbar=no,location=no,status=yes,menubar=no");
	}
	
	/**************************************查询出工作流实例********************************************/
	function findProcessDefinitionInstances(_procDefId){
		procDefId = _procDefId;
		CtitJbpmAction.findProcessDefinitionInstances(_procDefId, findProcessDefinitionInstancesBack);
	}
	
	function findProcessDefinitionInstancesBack(oData){
		list_pager = new Pager(oData,setDataToProcDefInsTable,"list_pager",10);
        var data = list_pager.getItemArray();
        setDataToProcDefInsTable(data);
        list_pager.generatePageNavigation(document.getElementById("process_page_nav"));
        list_pager.generatePageNavigation(document.getElementById("process_page_nav_top"));
        generateBackToProcessButton();
	}
	
	function generateBackToProcessButton(){
		var div = document.getElementById("right_div");	
		var innerHtml = div.innerHTML;
		if(currentPageType == 0){
			var innerHtml = "<a class=\"button1\" href=\"javascript:backToProcessListPage();\"><span>返回</span></a>";
			var div = document.getElementById("backToPage");
			div.innerHTML = innerHtml;
		} else {
			var innerHtml = "<a class=\"button1\" href=\"javascript:backToProcessVersionPage();\"><span>返回</span></a>";
			var div = document.getElementById("backToPage");
			div.innerHTML = innerHtml;
		}
	}
	
	function backToProcessVersionPage(){
		var baseDiv = document.getElementById("processins_base_detail");
		var backDiv = document.getElementById("backToPage");
		var keywordDiv = document.getElementById("keyword");
	   	var searchDiv = document.getElementById("search");
		backDiv.innerHTML = "";
		baseDiv.innerHTML = "";
		baseDiv.className = "";
		keywordDiv.style.display = "block";
		searchDiv.style.display = "block";
		loadProcessAllVersions(procDefName);
	}
	
	/**************************************查询出工作流实例的详情****************************************/
	function findProcessInstaceDetails(procInsId){
		CtitJbpmAction.findProcessDefintionInstanceDetails(procInsId, findProcessInstaceDetailsBack);
	}
	
	function findProcessInstaceDetailsBack(oData){
		setDataToProcDefInsBaseDetailsTable(oData);
		list_pager = new Pager(oData.variables,setDataToProcDefInsVariableDetailsTable,"list_pager",10);
        var data = list_pager.getItemArray();
        setDataToProcDefInsVariableDetailsTable(data);
        list_pager.generatePageNavigation(document.getElementById("process_page_nav"));
        list_pager.generatePageNavigation(document.getElementById("process_page_nav_top"));
        generateBackToInstanceDetailPageButton();
	}
	
	function generateBackToInstanceDetailPageButton(){
		var innerHtml = "<a class=\"button1\" href=\"javascript:backToInstanceDetailPage();\"><span>返回</span></a>";
		var div = document.getElementById("backToPage");
		div.innerHTML = innerHtml;
	}
	
	function backToInstanceDetailPage(){
		var baseDiv = document.getElementById("processins_base_detail");
		var backDiv = document.getElementById("backToPage");
		var keywordDiv = document.getElementById("keyword");
	   	var searchDiv = document.getElementById("search");
		backDiv.innerHTML = "";
		baseDiv.innerHTML = "";
		baseDiv.className = "";
		keywordDiv.style.display = "block";
		searchDiv.style.display = "block";
		findProcessDefinitionInstances(procDefId);
	}
	
	function findProcessInstancesByName(){
		var name = document.getElementById("value").value;
		if(name){
			CtitJbpmAction.findProcessInstancesByPartOfName(procDefId, name, findProcessDefinitionInstancesBack);
		} else {
			alertMessage("请输入查询关键字");
		}
	}
	
	/**************************************查询出指定工作流的历史版本****************************************/
	function loadProcessAllVersions(processName){
		procDefName = processName;
		currentPageType = 1;
		CtitJbpmAction.findProcessAllVersions(processName, loadProcessAllVersionsBack);
	}
	
	function loadProcessAllVersionsBack(oData){
		list_pager = new Pager(oData,setDataToProcessVersionsTable,"list_pager",10);
        var data = list_pager.getItemArray();
        setDataToProcessVersionsTable(data);
        list_pager.generatePageNavigation(document.getElementById("process_page_nav"));
        list_pager.generatePageNavigation(document.getElementById("process_page_nav_top"));
        generateBackToProcessListPageButton();
	}
	
	function generateBackToProcessListPageButton(){
		var innerHtml = "<a class=\"button1\" href=\"javascript:backToProcessListPage();\"><span>返回</span></a>";
		var div = document.getElementById("backToPage");
		div.innerHTML = innerHtml;
	}
	
	function backToProcessListPage(){
		var baseDiv = document.getElementById("processins_base_detail");
		var backDiv = document.getElementById("backToPage");
		var keywordDiv = document.getElementById("keyword");
	   	var searchDiv = document.getElementById("search");
		var doSearch = document.getElementById("doSearch");
		backDiv.innerHTML = "";
		baseDiv.innerHTML = "";
		baseDiv.className = "";
		keywordDiv.style.display = "block";
		searchDiv.style.display = "block";
	   	if(doSearch == null){
	   		var a = "<a class=\"button1\" href=\"javascript:loadProcessDefinitionByName();\" id=\"doSearch\"><span>搜索</span></a>";
	   		searchDiv.innerHTML = a;
	   	} else {
	   		doSearch.setAttribute("href","javascript:loadProcessDefinitionByName();");
	   	}
		loadAllProcessDefinitions();
	}
	
	/*
		数据导入表格
	*/
	function setDataToProcessTable(data){		
		var innerHtml = "<table  class=\"t2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
	 	 					"<thead>"+
						  		"<tr>"+
						  			//"<td class=\"title2\" style=\"border-left:1px solid #fff;\">ID</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程名称</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">版本号</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">操作</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">历史版本</td>"+
						  		"</tr>"+
						  	"</thead>"+
							"<tbody id=\"processList\">"+
						    "</tbody>"+
						"</table>";
		var div = document.getElementById("right_div");					
	   	div.innerHTML = innerHtml;
	
		var rowIndex = 0;
		var colIndex = 0;
		var cellFuncs = [
					//function(data){return data.id;},
					function(data){
						var processId = data.id;
        				var updateLink = document.createElement("<A href='processupdate.html?procId="+processId+" ' ></a>");
        				updateLink.innerText = data.name;
        				return updateLink;
        			},	
					function(data){return data.version},
					function(data){
			            return "<A href=\"javascript:deleteProcessDefinition("+data.id+");\">删除</a>&nbsp;&nbsp;"+
			            	   "<A href=\"javascript:openProcessDefinitionXML("+data.id+");\">XML</a>&nbsp;&nbsp;"+
			            	   "<A href=\"javascript:findProcessDefinitionInstances("+data.id+");\">实例</a>"; 
					},
					function(data){
						var processName = data.name;
			            var versionLink = document.createElement("<A href=\"javascript:loadProcessAllVersions('"+processName+"');\"></a>");  
			            versionLink.innerText = "打开";
			            return versionLink; 
					}
				];
		
		var tr_td_options={
				rowCreator:function(options) {
						var row = document.createElement("tr");
						if(rowIndex % 2 == 0){
							row.className = "td2";
						}
						rowIndex = rowIndex + 1;
						return row;
					},
				cellCreator:function(options) {
						var td = document.createElement("td");
						//if(colIndex == 0){
						//	td.setAttribute("width", "8%");
						//} 
						if(colIndex == 0){
							td.setAttribute("width", "50%");
						} 
						if(colIndex == 1){
							td.setAttribute("width", "10%");
						}
						if(colIndex == 2){
							td.setAttribute("width", "20%");
						}
						colIndex = colIndex + 1;
						return td;
					}
				};
				
		
		dwr.util.removeAllRows('processList');
		dwr.util.setEscapeHtml(false);
		dwr.util.addRows("processList",data, cellFuncs, tr_td_options);
	}
	
	/*
		显示所有版本
	*/
	function setDataToProcessVersionsTable(data){		
		var innerHtml = "<table  class=\"t2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
	 	 					"<thead>"+
						  		"<tr>"+
						  			//"<td class=\"title2\" style=\"border-left:1px solid #fff;\">ID</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程名称</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">版本号</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">操作</td>"+
						  		"</tr>"+
						  	"</thead>"+
							"<tbody id=\"processList\">"+
						    "</tbody>"+
						"</table>";
		var div = document.getElementById("right_div");					
	   	div.innerHTML = innerHtml;
	   	
	   	var reflushDiv = document.getElementById("reflush");
	   	var searchDiv = document.getElementById("search");
	   	var importDiv = document.getElementById("import");
	   	var exportDiv = document.getElementById("export");
	   	
	   	if(reflushDiv) reflushDiv.style.display = "block";
	   	if(importDiv) importDiv.style.display = "block";
	   	if(exportDiv) exportDiv.style.display = "block";
	
		var rowIndex = 0;
		var colIndex = 0;
		var cellFuncs = [
					//function(data){return data.id;},
					function(data){
						var processId = data.id;
        				var updateLink = document.createElement("<A href='processupdate.html?procId="+processId+" ' ></a>");
        				updateLink.innerText = data.name;
        				return updateLink;
        			},	
					function(data){return data.version},
					function(data){
			            return "<A href=\"javascript:deleteProcessDefinition("+data.id+");\">删除</a>&nbsp;&nbsp;"+
			            	   "<A href=\"javascript:openProcessDefinitionXML("+data.id+");\">XML</a>&nbsp;&nbsp;"+
			            	   "<A href=\"javascript:findProcessDefinitionInstances("+data.id+");\">实例</a>"; 
					}
				];
		
		var tr_td_options={
				rowCreator:function(options) {
						var row = document.createElement("tr");
						if(rowIndex % 2 == 0){
							row.className = "td2";
						}
						rowIndex = rowIndex + 1;
						return row;
					},
				cellCreator:function(options) {
						var td = document.createElement("td");
						//if(colIndex == 0){
						//	td.setAttribute("width", "8%");
						//} 
						if(colIndex == 0){
							td.setAttribute("width", "50%");
						} 
						if(colIndex == 1){
							td.setAttribute("width", "10%");
						}
						if(colIndex == 2){
							td.setAttribute("width", "20%");
						}
						colIndex = colIndex + 1;
						return td;
					}
				};
				
		
		dwr.util.removeAllRows('processList');
		dwr.util.setEscapeHtml(false);
		dwr.util.addRows("processList",data, cellFuncs, tr_td_options);
	}
	
	/*
		数据导入表格
	*/
	function setDataToProcDefInsTable(data){	
		var innerHtml = "<table  class=\"t2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
	 	 					"<thead>"+
						  		"<tr>"+
						  			//"<td class=\"title2\" style=\"border-left:1px solid #fff;\">工作流ID</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程名称</td>"+
						   	 		//"<td class=\"title2\" style=\"border-left:1px solid #fff;\">实例ID</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程开始时间</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程结束时间</td>"+
						   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程当前所处节点</td>"+
						  		"</tr>"+
						  	"</thead>"+
							"<tbody id=\"processList\">"+
						    "</tbody>"+
						"</table>";
		var div = document.getElementById("right_div");					
	   	div.innerHTML = innerHtml;
	   	
	   	var keywordDiv = document.getElementById("keyword");
	   	var reflushDiv = document.getElementById("reflush");
	   	var searchDiv = document.getElementById("search");
	   	var importDiv = document.getElementById("import");
	   	var exportDiv = document.getElementById("export");
	   	var processimpDiv = document.getElementById("processimp");
	   	var processexpDiv = document.getElementById("processexp");
	   	
	   	
	   	if(reflushDiv) 
	   		reflushDiv.style.display = "none";
	   	if(importDiv) 
	   		importDiv.style.display = "none";
	   	if(exportDiv) 
	   		exportDiv.style.display = "none";
	   	if(processimpDiv) 
	   		processimpDiv.style.display = "none";
	   	if(processexpDiv) 
	   		processexpDiv.style.display = "none";
	   	
	   	if(keywordDiv.innerHTML == ""){
	   		var input = "请输入关键词：<input type=\"text\" name=\"textfield\" id=\"value\"/>";
	   		keywordDiv.innerHTML = input;
	   	}
	   	
	   	var doSearch = document.getElementById("doSearch");
	   	if(doSearch == null){
	   		var a = "<a class=\"button1\" href=\"javascript:findProcessInstancesByName();\" id=\"doSearch\"><span>搜索</span></a>";
	   		searchDiv.innerHTML = a;
	   	} else {
	   		doSearch.setAttribute("href","javascript:findProcessInstancesByName()");
	   	}
	
		var rowIndex = 0;
		var colIndex = 0;
		var cellFuncs = [
					//function(data){return data.procDefId;},
					function(data){return data.procDefName;},
					//function(data){return data.procInsId;},
					function(data){return new Date(data.procInsStartDate).format("yyyy-MM-dd hh:mm:ss");},
					function(data){ var endDate = data.procInsEndDate;
									if(endDate == null) return "审批流程未结束";
									return new Date(data.procInsEndDate).format("yyyy-MM-dd hh:mm:ss");},
					function(data){return "<a href=\"javascript:findProcessInstaceDetails("+data.procInsId+");\" alt=\"详细信息\">"+data.currentTaskName+"</a>"}
				];
		
		var tr_td_options={
				rowCreator:function(options) {
						var row = document.createElement("tr");
						if(rowIndex % 2 == 0){
							row.className = "td2";
						}
						rowIndex = rowIndex + 1;
						return row;
					},
				cellCreator:function(options) {
						var td = document.createElement("td");
						//if(colIndex == 0){
						//	td.setAttribute("width", "8%");
						//} 
						if(colIndex == 0){
							td.setAttribute("width", "30%");
						} 
						if(colIndex == 1 || colIndex == 2){
							td.setAttribute("width", "20%");
						}
						colIndex = colIndex + 1;
						return td;
					}
				};
				
		
		dwr.util.removeAllRows('processList');
		dwr.util.setEscapeHtml(false);
		dwr.util.addRows("processList",data, cellFuncs, tr_td_options);
	}
	
	/*
		数据导入表格
	*/
	function setDataToProcDefInsBaseDetailsTable(data){	
		var innerHtml = "<table  class=\"t2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
							//"<tr>"+
					  		//	"<td class=\"title2\" style=\"border-left:1px solid #fff;\">工作流ID</td>"+
					  		//	"<td style=\"border-left:1px solid #fff;\">"+data.procDefId+"</td>"+
					  		//"</tr>"+
					  		"<tr>"+
					   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程名称</td>"+
					   	 		"<td style=\"border-left:1px solid #fff;\">"+data.procDefName+"</td>"+
					   	 	"</tr>"+
					   	 	//"<tr>"+
					   	 	//	"<td class=\"title2\" style=\"border-left:1px solid #fff;\">实例ID</td>"+
					   	 	//	"<td style=\"border-left:1px solid #fff;\">"+data.procInsId+"</td>"+
					   	 	//"</tr>"+
					   	 	"<tr>"+
					   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程开始时间</td>"+
					   	 		"<td style=\"border-left:1px solid #fff;\">"+new Date(data.procInsStartDate).format('yyyy-MM-dd hh:mm:ss')+"</td>"+
					   	 	"</tr>"+
					   	 	"<tr>"+
					   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程结束时间</td>"+
					   	 		"<td style=\"border-left:1px solid #fff;\">"+new Date(data.procInsEndDate).format('yyyy-MM-dd hh:mm:ss')+"</td>"+
					   	 	"</tr>"+
					   	 	"<tr>"+
					   	 		"<td class=\"title2\" style=\"border-left:1px solid #fff;\">审批流程当前所处节点</td>"+
					   	 		"<td style=\"border-left:1px solid #fff;\">"+data.currentTaskName+"</td>"+
					   	 	"</tr>"+
						"</table>";
		var div = document.getElementById("processins_base_detail");	
		div.className = "right_div2";				
	   	div.innerHTML = innerHtml;
	}
	
	function setDataToProcDefInsVariableDetailsTable(data){
		var innerHtml = "<table  class=\"t2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
							"<thead>"+
								"<tr>"+
									"<td class=\"title2\" style=\"border-left:1px solid #fff;\">变量名</td>"+
									"<td class=\"title2\" style=\"border-left:1px solid #fff;\">变量值</td>"+
								"</tr>"+
							"</thead>"+
							"<tbody id=\"processList\">"+
						    "</tbody>"+
						"</table>";
		var div = document.getElementById("right_div");					
	   	div.innerHTML = innerHtml;
	   	
	   	var keywordDiv = document.getElementById("keyword");
	   	var searchDiv = document.getElementById("search");
	   	var reflushDiv = document.getElementById("reflush");
	   	var importDiv = document.getElementById("import");
	   	var exportDiv = document.getElementById("export");
	   	var processimpDiv = document.getElementById("processimp");
	   	var processexpDiv = document.getElementById("processexp");
	   	
	   	if(keywordDiv) 
	   		keywordDiv.style.display = "none";
	   	if(reflushDiv)
	   		reflushDiv.style.display = "none";
	   	if(searchDiv)
	   		searchDiv.style.display  = "none";
	   	if(importDiv)
	   		importDiv.style.display  = "none";
	   	if(exportDiv)
	   		exportDiv.style.display  = "none";
	   	if(processimpDiv)
	   		processimpDiv.style.display = "none";
		if(processexpDiv)
	   		processexpDiv.style.display = "none";
		var rowIndex = 0;
		var colIndex = 0;
		var cellFuncs = [
					function(data){return data.name;},
					function(data){
									var value = data.value;
								    if(value == "" || value == null){
								    	value = "&nbsp;";
								    }
								    return value;
								  }
				];
		
		var tr_td_options={
				rowCreator:function(options) {
					var row = document.createElement("tr");
					if(rowIndex % 2 == 0){
						row.className = "td2";
					}
					rowIndex = rowIndex + 1;
					return row;
				},
				cellCreator:function(options) {
						var td = document.createElement("td");
						if(colIndex == 0){
							td.setAttribute("width","50%");
						}
						return td;
					}
				};
		dwr.util.removeAllRows('processList');
		dwr.util.setEscapeHtml(false);
		dwr.util.addRows("processList",data, cellFuncs, tr_td_options);
	}
	
	/*function generateBackToPageButton(){
		var innerHtml = "<a class=\"button1\" href=\"javascript:backToPreviousPage();\"><span>返回</span></a>";
		var div = document.getElementById("backToPage");
		div.innerHTML = innerHtml;
	}*/
	
	function gotoFirstPage(pageSize){
        CtitJbpmAction.getPageData(1, pageSize, pageDataBack);
       	currentPageIndex = 1;
    }
    
    function gotoNextPage(pageSize){
         var nextPageIndex = getNextPage();
	     CtitJbpmAction.getPageData(nextPageIndex, pageSize, pageDataBack);
         currentPageIndex = nextPageIndex; 
    }
    
    function gotoPreviousPage(pageSize){
    	 var prePageIndex = getPreviousPage();
         CtitJbpmAction.getPageData(prePageIndex, pageSize, pageDataBack);
    	 currentPageIndex = prePageIndex;
    }
    
    function gotoLastPage(pageSize){
	     CtitJbpmAction.getPageData(pageCount, pageSize, pageDataBack);
         currentPageIndex = pageCount;
    }
	
	function pageDataBack(oData){
		setDataToProcessTable(oData);
	}
	
	function getNextPage(){
		var nextPage = currentPageIndex + 1;
        if(nextPage > pageCount){
            nextPage = pageCount;
        }
        return nextPage;
    }
      
    function getPreviousPage(){
       var prePage = currentPageIndex - 1;
   	   if(prePage < 1){
           prePage = 1;
   	   }    
       return prePage;
    }
    
   	function displayProcessimpDiv(){
		var procImpDiv = document.getElementById("processimp");
		var procExpDiv = document.getElementById("processexp");
		procImpDiv.style.display = "block";
		procExpDiv.style.display = "none";
	}
	
	function displayProcessexpDiv(){
		var procExpDiv = document.getElementById("processexp");
		var procImpDiv = document.getElementById("processimp");
		procExpDiv.style.display = "block";
		procImpDiv.style.display = "none";
	}
	
	function closeProcessexpDiv(){
		var procExpDiv = document.getElementById("processexp");
		procExpDiv.style.display = "none";
	}
	
	function closeProcessimpDiv(){
		var procImpDiv = document.getElementById("processimp");
		procImpDiv.style.display = "none";
	}
    
    /*
    	导入工作流
    */
	function processImport(){
		var file = document.getElementById("imppath");
		var path = file.value;
		if(path != ""){
			window.location = "processupdate.html?path="+path;
		} else {
			alertMessage("请选择要导入的工作流。");
		}
	}
	
	/*
		导出部分工作流
	*/
	function processExport(){
		var value = document.getElementById("procIds").value;
		var path = document.getElementById("exppath").value;
		if(value){
			 var reg = /^\d+[($|\,\d+$)]*/;
			 if(value.match(reg)){
			    if(path != ""){
				 	var ids = value.split(",");					
					showLoading("正在导出工作流，请稍候......");
				 	CtitJbpmAction.processExport(ids, {
				 							 callback:processExportBack, 
				 							 errorHandler:errorHandle
				 							 });
				 } else {
				 	alertMessage("请选择要导出工作流的路径。");
				 }
			} else {
				alertMessage("多个ID之间以英文逗号隔开，如：1,2,3,4,5");
			}
		} else {
			alertMessage_5("提示：\n如果不输入ID，将导出所有的工作流");
		}
	}
	
	/*
		导出全部工作流
	*/
	function exportAllProcesses(){
		var path = document.getElementById("exppath").value;
		if(path != ""){
			showLoading("正在导出工作流，请稍候......");
			CtitJbpmAction.processAllExport({
											callback:processExportBack,
											errorHandler:errorHandle
										});
		} else {
	 		alertMessage("请选择要导出工作流的路径。");
	 	}
	}
	
	function processExportBack(procDefInfos){
		writeFileToDisk(procDefInfos);
		alertInfo("工作流导出成功！");
		hideLoading();
	}
	
	function processAllExportBack(procDefInfos){
		if(procDefInfos.length > 0){
			writeFileToDisk(procDefInfos);
			exportAllProcesses();
		} else {
			alertInfo("工作流导出成功！");
			hideLoading();
		}
	}
	
	function writeFileToDisk(procDefInfos){
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var path = document.getElementById("exppath").value;
		path = path.replace("\\\\", "/") + "/";
		for(var i=0; i<procDefInfos.length; i++){
			var procDefInfo = procDefInfos[i];
			var xmlName =  procDefInfo.procDefName;
			var fileName_1 = xmlName+".xml";
			var fileName_2 = xmlName+".schema.xml";
			var path_1 = path + fileName_1;
			var path_2 = path + fileName_2;
			var tf_1 = fso.CreateTextFile(path_1, true);
			var tf_2 = fso.CreateTextFile(path_2, true);
			tf_1.Write(procDefInfo.xml);
			tf_2.Write(procDefInfo.schema);
			tf_1.close();
			tf_2.close();
		}
	}
	
	function errorHandle(errorMsg, exception){
		var message = null;
		if(errorMsg){
			message = errorMsg;
		} else if(exception.cause){
			message = exception.cause.message;
		} else {
			message = "";
		}
		alertMessage(message);
		hideLoading();
	}
/****************************列出本地磁盘和文件夹**************************************/	
	function getSubForderList(fldr){
	    var fcFolder = new Enumerator(fldr.SubFolders); //子文件夹   
	    var list = new Array;    
	    for (;   !fcFolder.atEnd();   fcFolder.moveNext()){   //枚举所有子文件夹 
	        list.push(fcFolder.item());
	    }
	    return list;
	}
	
	
	function bindSelect(sel,forder){
	    var f = document.getElementById("exppath");
	    if(forder == "null" || forder.IsRootFolder){
	        f.value = "";
	        binDriver();
	        return;        
	    }
	    f.value = forder;
	    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
	    var fldr = fso.GetFolder(forder);  
	    var list = getSubForderList(fldr);
	    while(sel.options.length >0){
	        sel.options.remove(0);
	    }
	    var oOption ;
	    oOption= document.createElement("OPTION");
	    sel.options.add(oOption);
	    oOption.innerText = "  刷新  ";
	    oOption.value = forder;
	    oOption= document.createElement("OPTION");
	    sel.options.add(oOption);
	    oOption.innerText = "\\..";
	    oOption.value = fldr.ParentFolder;
	    for(var i=0;i<list.length;i++){
	        oOption = document.createElement("OPTION");
	        sel.options.add(oOption);
	        oOption.innerText = list[i].Name; //list[i].ShortName;
	        oOption.value = list[i];
	    }    
	}
	
	function getForder(sel){
	    bindSelect(sel,sel.options[sel.selectedIndex].value);
	}
/**********************************找出局的工作流****************************************/
	/*
		获取所有的工作流
	*/
	function findDepartmentProcessDefinition(){
		dwr.engine.setAsync(false);
		CtitJbpmAction.findWorkflows(findDepartmentProcessDefinitionBack);
		dwr.engine.setAsync(true);
	}
	
	/*
		回调函数，解析xml，从而获取所需的工作流相关数据
	*/
	function findDepartmentProcessDefinitionBack(data){
		if(data != null || data != ""){
			var xml = new ActiveXObject("Microsoft.xmldom");
			xml.async = "false";
			xml.loadXML(data);
			var workflows = xml.getElementsByTagName("workflow");
			var workflowNames = new Array();
			for(var i=0; i<workflows.length; i++){
				var wf = workflows(i).xml;
				var xml_wf = new ActiveXObject("Microsoft.xmldom");
				xml_wf.async = "false";
				xml_wf.loadXML(wf);
				var workflowName = (xml_wf.getElementsByTagName("name"))[0].text;
				workflowNames[i] = workflowName;
			}
			procNames = workflowNames;
			CtitJbpmAction.findDepartmentProcessDefinition(workflowNames, loadProcessDefinitionByNameBack);
		}
 	}
	
	
/***************************************************************************/
	
	function openPage(){
		var mainPage = window.parent.document.getElementById("main");
		mainPage.setAttribute("src","processlist.html");
	}
	
	function isDeptManager(){
		var grouproles = window.parent.parent.user.grouproles.split(";");
		for(var i=0; i<grouproles.length; i++){
			if(grouproles[i] == "部门管理员"){
				return true;
			}
		}
		return false;
	}
	
	
	document.onkeypress = function(event){
        var e = event || window.event;
    	if(e.keyCode == 13){
    		if(document.getElementById("import").style.display == "block")
    			loadProcessDefinitionByName();
    		else 
    			findProcessInstancesByName();
    	}
     }
	
	